<template>
  <el-button @click="download"
             :loading="isLoading && downloadPath === model"
             type="success" size="small"
             :disabled="model === '' || model === null">
    <template v-if="model !== '' || model !== null">
      <slot></slot>
    </template>
    <template v-else>
      还未上传相关文件
    </template>
  </el-button>
</template>

<script setup lang="ts">
import {useDownloadFile} from "../query/file.ts";

const model = defineModel<string>({
  default: ""
});

let {fileName} = defineProps<{
  fileName: string
}>();

let {downloadPath, isLoading, setFileName, refetch} = useDownloadFile();

const download = () => {
  downloadPath.value = model.value
  setFileName(fileName)
  refetch()
}
</script>

<style scoped>

</style>